﻿Imports FinanceiroDAL
Imports FinanceiroBLL
Public Class FormaPagamentoCAD
    Dim objBLL As New FormasPgtoBLL
    Dim operacao As Char
   
#Region "Load"
    Private Sub FormaPagamentoCAD_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        objconexao.carregaCombo(CBStatus, "Generico.Gen_Status", "sta_codigo", "sta_descricao", "sta_codigo=1 or sta_codigo=2", "sta_descricao")
        TBDescricao.Focus()
        CBStatus.SelectedValue = 1
        If (Not IsNothing(lcodigo.Text) And lcodigo.Text.Trim <> "") Then
            objBLL = New FormasPgtoBLL(Val(lcodigo.Text))
            carregacampos()
            operacao = "A"
            lcodigo.Visible = True
        Else : operacao = "I"
        End If
    End Sub
#End Region
#Region "Carrega Campos"
    Public Sub carregacampos()
        lcodigo.Text = objBLL.pagcodigo
        TBDescricao.Text = objBLL.pagdescricao
        CBStatus.SelectedValue = objBLL.statuscodigo
    End Sub
#End Region
#Region "Limpar"
    Public Sub limpar()
        Me.lcodigo.Text = Nothing
        Me.TBDescricao.Clear()
        Me.CBStatus.SelectedValue = 0
        Me.objBLL = Nothing

    End Sub
#End Region
    Private Sub TSBGravar_Click(sender As System.Object, e As System.EventArgs) Handles TSBGravar.Click
        Try
            'carregacampos()

            objBLL = New FormasPgtoBLL((Val(lcodigo.Text)), CBStatus.SelectedValue, Trim(TBDescricao.Text))
            If operacao = "I" Then
                If (objBLL.inserir()) Then
                    MessageBox.Show("Forma de Pagamento inserida com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    limpar()
                    Me.Close()
                Else : MessageBox.Show("A Forma de Pagamento não pode ser inserida", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            Else
                If (objBLL.alterar()) Then
                    MessageBox.Show("Forma de Pagamento alterada com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                    limpar()
                    Me.Close()
                Else : MessageBox.Show("A Forma de Pagamento não pôde ser alterada", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try

    End Sub

    Private Sub FormaPagamentoCAD_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        limpar()
    End Sub

    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Me.Close()
        limpar()
    End Sub

    Private Sub TBDescricao_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TBDescricao.KeyPress
        If Not Char.IsLetter(e.KeyChar) And e.KeyChar = vbBack And Not e.KeyChar = "." And Not e.KeyChar = "," And e.KeyChar = "" Then
            e.Handled = True
        End If
    End Sub

    Private Sub LDescricao_Click(sender As System.Object, e As System.EventArgs) Handles LDescricao.Click

    End Sub

    Private Sub LStatus_Click(sender As System.Object, e As System.EventArgs) Handles LStatus.Click

    End Sub
End Class